import axios from 'axios'
import {getToken} from '@/utils/auth.js'
const service = axios.create({
  // baseURL: '/api',
  baseURL: '/api',
  timeout: 10000
})
service.interceptors.request.use(
  (config) => {
    const res =  getToken()
    if (res) {
      // config.headers.Authorization = `Bearer ${res}`
      config.headers.Authorization = res
    }
    return config
  },
  (error) => Promise.reject(error)
)
//响应拦截器
service.interceptors.response.use(
  (response) => {
    console.log(response)
    if (response.data instanceof Blob) return response.data
    return response.data
  },
  (error) => {
    return Promise.reject(new Error(error))
  }
)
export default service
